﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace ShanNiang.Mvvm.Converters
{
    [ValueConversion(typeof(string), typeof(Brush))]
    public class CodeToBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                var valueStr = (string)value;
                if (!string.IsNullOrEmpty(valueStr))
                {
                    return new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
                }
            }
            if (parameter != null )
            {
                if (parameter is Color)
                {
                    return new SolidColorBrush((Color)parameter);
                }
                else if (parameter is Brush) 
                {
                    return (Brush)parameter;
                }
            }
            return new SolidColorBrush(Color.FromArgb(0xff,0xe8,0xe8,0xe8));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
